Day 6 - While Loop & Karel


Posted by pei_______ on 2022-04-16

learning from 100 Days of Code: The Complete Python Pro Bootcamp for 2022


(1) Defining function
def my_function():
Do this
Then do this
Finally do this

(2) Calling function
my_function()

(3) while loop
while something_is_true
Do this
Then do this


play in Reeborg's World

def turn_right():
    turn_left()
    turn_left()
    turn_left()

def jump():
    turn_left()
    while not right_is_clear():
        move()
    turn_right()
    move()
    turn_right()
    while front_is_clear():
        move()
    turn_left()

while not at_goal():
    if front_is_clear():
        move()
    if wall_in_front():
        jump()

def turn_right():
    turn_left()
    turn_left()
    turn_left()

while not at_goal():
    if wall_on_right() and wall_in_front():
        turn_left()
    elif wall_in_front() or right_is_clear():
        turn_right()
        move()
    else:
        move()

#Python #課堂筆記 #100 Days of Code







Related Posts

七天打造自己的 Google Map 應用入門 - Day03

七天打造自己的 Google Map 應用入門 - Day03

[FE302] React 基礎 - hooks 版本:再度中場休息

[FE302] React 基礎 - hooks 版本:再度中場休息

day_03: 我好像有點懂函數式了...

day_03: 我好像有點懂函數式了...


Comments